Skip to content

Close MockWebServer connections on failure - #9875

Merged
yschimke merged 3 commits into
lysine-dev:mainfrom
FletchMcKee:close-mws-connections-on-fail
Nov 21, 2026
Merged

yschimke merged 3 commits into
lysine-dev:mainfrom
FletchMcKee:close-mws-connections-on-fail

Conversation

@FletchMcKee

Copy link
Copy Markdown
Contributor

MockWebServer's serveConnection left the socket open if handle() threw which would leave the client hanging until it timed out.

I was trying to see if I could help with the openjdk8alpn failures and discovered this. In my fork I moved the jdk8alpn Gradle logic to testing-conventions and it ended up with a lot of slow tests. Most had an unhelpful summary like this:

java.util.concurrent.TimeoutException: https() timed out after 30 seconds
	at java.util.ArrayList.forEach(ArrayList.java:1257)
	at java.util.ArrayList.forEach(ArrayList.java:1257)
Caused by: org.junit.jupiter.api.AssertTimeoutPreemptively$ExecutionTimeoutException: Execution timed out in thread junit-timeout-thread-77
	at java.net.SocketInputStream.socketRead0(Native Method)
  ...

But an error output like this:

Exception in thread "MockWebServer TaskRunner" java.lang.NoSuchMethodError: sun.security.ssl.SignatureAndHashAlgorithm.getPreferableAlgorithm(Ljava/util/Collection;Ljava/lang/String;)Lsun/security/ssl/SignatureAndHashAlgorithm;
	at sun.security.ssl.ServerHandshaker.trySetCipherSuite(ServerHandshaker.java:1395)
	...
	at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1379)
	at mockwebserver3.MockWebServer$SocketHandler.handle(MockWebServer.kt:484)
	at mockwebserver3.MockWebServer.serveConnection$lambda$0(MockWebServer.kt:427)
	at okhttp3.internal.concurrent.TaskQueue$execute$1.runOnce(TaskQueue.kt:112)

I can share those test reports if desired. Before this change the reports would be incomplete since I canceled the jobs as they were still running after an hour. With this change they completed in ~13 minutes with 700+ test failures, but most were NoSuchMethodErrors or NoSuchFieldErrors.

I haven't figured out the fix for that, but I thought this might still be helpful.

@FletchMcKee
FletchMcKee force-pushed the close-mws-connections-on-fail branch from f990191 to 6f50a90 Compare November 20, 2026 16:31
@FletchMcKee

Copy link
Copy Markdown
Contributor Author

Realized it might be helpful to link to those workflows.

Here is where it completes after closing the connections:

https://github.com/FletchMcKee/okhttp/actions/runs/44563014825

And one of the long workflows:

https://github.com/FletchMcKee/okhttp/actions/runs/44551265593

@yschimke
yschimke enabled auto-merge (squash) November 21, 2026 12:25
@yschimke
yschimke merged commit ec72d3d into lysine-dev:main Nov 21, 2026
39 of 41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants